package main.java.com.epam;

public class ComplexNumber {

	private double Re;
	private double Im;

	public ComplexNumber() {
	}

	public ComplexNumber (double Re, double Im){
		this.Re = Re;
		this.Im = Im;
	}

	public double getRe() {
		return Re;
	}

	public void setRe(double Re) {
		this.Re = Re;
	}

	public double getIm() {
		return Im;
	}

	public void setIm(double Im) {
		this.Im = Im;
	}

	public static ComplexNumber add(ComplexNumber a, ComplexNumber b) {
		return new ComplexNumber(a.getRe() + b.getRe(), a.getIm() + b.getIm());
	}

	public static ComplexNumber sub(ComplexNumber a, ComplexNumber b) {
		return new ComplexNumber(a.getRe() - b.getRe(), a.getIm() - b.getIm());
	}

	public static ComplexNumber mul(ComplexNumber a, ComplexNumber b) {
		return new ComplexNumber(
				a.getRe() * b.getRe()- a.getIm() * b.getIm(),
				a.getIm() * b.getRe() + a.getRe() * b.getIm()
				);
	}

	public static ComplexNumber div(ComplexNumber a, ComplexNumber b) {
		return new ComplexNumber(
				(a.getRe() * b.getRe() + a.getIm() * b.getIm()) / (b.getRe() * b.getRe() + b.getIm() * b.getIm()),
				(a.getIm() * b.getRe() - a.getRe() * b.getIm())/ (b.getRe() * b.getRe() + b.getIm() * b.getIm())
				);
	}

	@Override
	public String toString() {
		return Re+"+i("+Im+")";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(Im);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(Re);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ComplexNumber other = (ComplexNumber) obj;
		if (Double.doubleToLongBits(Im) != Double.doubleToLongBits(other.Im))
			return false;
		if (Double.doubleToLongBits(Re) != Double.doubleToLongBits(other.Re))
			return false;
		return true;
	}




}
